#include "game.hpp"
#include "board.hpp"

namespace gomoku{

    game::game(int height, int width):board{height,width}{

    }

    game::game(int height, int width, int init_status, point_status *init_layout):board{height,width,init_layout}{
        _status = init_status;
    }

    /* 输出的文件依次记录一下内容:
    ** 游戏模式
    ** 游戏状态
    ** 棋盘行数
    ** 棋盘列数
    ** 棋盘上棋子的布局
    */
    void game::save(std::ofstream &outfile) const{
        int tmp;
        tmp = game_mode();
        outfile.write((char*)&tmp,sizeof(int));
        outfile.write((char*)&_status,sizeof(int));
        tmp = board.height();
        outfile.write((char*)&tmp,sizeof(int));
        tmp = board.width();
        outfile.write((char*)&tmp,sizeof(int));
        for (int i=0;i<board.height();++i){
            for (int j=0;j<board.width();++j){
                tmp = int(board[point{i,j}]);
                outfile.write((char*)&tmp,sizeof(int));
            }
        }
    }

}